package test;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class T2 {

	private static class QueueByStack{
		
		private Stack<Integer> s1 = new Stack<Integer>();  
		private Stack<Integer> s2 = new Stack<Integer>();
//		private Stack s3 = new Stack();s
		
		private void offer(int src){
			s1.push(src);
		}
		private Integer poll() {
			if (s2.isEmpty()) {
				while (!s1.isEmpty()) {
					s2.push(s1.pop());
				}
			}
			return s2.pop();
		}
		
		private void print(){
			for(Integer x:s1){
				System.out.print(x+"-");
			}
			System.out.println();
			for(Integer x:s2){
				System.out.print(x+"-");
			}
		}
		 
	}
	
//    for (Integer x : q) { 
//        System.out.println(x); 
//} 
//System.out.println("-------2-----"); 
////队列方式遍历，元素逐个被移除 
//while (q.peek() != null) { 
//        System.out.println(q.poll()); 
//} 
	
	private static class StackByQueue{
		private Queue<Integer> q1= new LinkedList();
		private Queue<Integer> q2= new LinkedList();
		
		private void push(int src){
			q1.offer(src);
			
		}
		private Integer pop(){
			while(q1.peek()!=null){
				q2.offer(q1.poll());
			}
		}
		
	}
	public static void main(String[] args) {
		QueueByStack qbs = new QueueByStack();
		qbs.offer(1);
		qbs.offer(2);
		qbs.offer(3);
		qbs.print();
		System.out.println(qbs.poll());
		qbs.offer(4);
		System.out.println(qbs.poll());
		qbs.print();
	}
}
